package com.vishu.collections;

import java.util.ArrayList;

public class ArrayListCommonDifferentElements {
	
	public static void main(String args[])
	{
	
		ArrayList<String> al1=new ArrayList<String>();
		al1.add("hi");
		al1.add("hello");
		al1.add("wassup");
		
		
		ArrayList<String> al2=new ArrayList<String>();
		al2.add("hi");
		al2.add("hello");
		al2.add("bye");
		
		
		ArrayList<String> similar=new ArrayList<String>();
		ArrayList<String> different=new ArrayList<String>();
		
		//A intersection B
		similar.addAll(al1);
		
		similar.retainAll(al2); // 'similar' intersection 'al2' ==> 'al1' intersection 'al2'
		
		System.out.println("Elements present in both the lists:"+similar);
		
		
		//(A union B) - (A intersection B)
		different.addAll(al1);
		different.addAll(al2);
		
		different.removeAll(similar);
		
		System.out.println("Elements which are not common to both:"+different);
		
		
		
	}

}
